<script src="<?php echo $conf['view_url'];?>js/md5.js"></script>
<?php
if(($route == 'thread' && $action == 'create') || ($route == 'post' && $action == 'update' && !empty($post) && $post['isfirst']!=0)) {
if(isset($LoadDatetimepicker)) $LoadDatetimepicker++;
else $LoadDatetimepicker=1;
?>

<!--
bootstrap datetimepicker 日历控件HTML HEAD
-->
<script src="plugin/<?php echo $ghx_cache->get_share_var(VAR_GHXTD); ?>/static/tempusdominus/js/moment-with-locales.min.js"></script>
<link href="plugin/<?php echo $ghx_cache->get_share_var(VAR_GHXTD); ?>/static/tempusdominus/css/tempusdominus-bootstrap-4.min.css"
      rel="stylesheet"/>
<link href="plugin/<?php echo $ghx_cache->get_share_var(VAR_GHXTD); ?>/static/tempusdominus/css/font-awesome.min.css"
      rel="stylesheet"/>
<script src="plugin/<?php echo $ghx_cache->get_share_var(VAR_GHXTD); ?>/static/tempusdominus/js/tempusdominus-bootstrap-4.min.js"></script>
<script type="text/javascript">//<![CDATA[
var autopickupkeyword_cfg = new Array();
    $(document).ready(function () {
        if (setMomentToCN() != false)
            $('#datetimepicker1').datetimepicker({
                format: 'YYYY-MM-DD hh:mm',
                locale: '<?php echo $conf['lang']?>',
                setStartDate: dateFormat("YYYY-mm-dd HH:MM", new Date()),
                buttons: {
                    showToday: true,
                    showClear: true,
                    showClose: true
                },
                icons: {
                    today: 'fa fa-caret-square-o-right',
                    clear: 'fa fa-trash-o',
                    close: 'fa fa-close'
                },
                tooltips: {
                    today: '今天',
                    clear: '清除',
                    close: '关闭',
                    selectMonth: '选择月份',
                    prevMonth: '上个月',
                    nextMonth: '下个月',
                    selectYear: '选择年份',
                    prevYear: '上一年',
                    nextYear: '下一年',
                    selectDecade: '选择时期',
                    prevDecade: '上个年代',
                    nextDecade: '下个年代',
                    prevCentury: '上个世纪',
                    nextCentury: '下个世纪',
                    incrementHour: '增加一小时',
                    pickHour: '选择小时',
                    decrementHour: '减少一小时',
                    incrementMinute: '增加一分钟',
                    pickMinute: '选择分',
                    decrementMinute: '减少一分钟',
                    incrementSecond: '增加一秒',
                    pickSecond: '选择秒',
                    decrementSecond: '减少一秒'
                },
            });
        $("#firstimg").change(function (tobj) {
            $("#firstimgview").prop('src', tobj.target.value);
        });

    });
<?php if(!empty($AutoPickupKeyWordCfg) && !empty($AutoPickupKeyWordCfg['enable'])) echo 'autopickupkeyword_cfg = '.xn_json_encode($AutoPickupKeyWordCfg).';'; ?>
//]]>
</script>
<?php
}
if(($route == 'thread' || $route == 'post')) {
?>
<script type="text/javascript">//<![CDATA[
    $(document).ready(function () {
        var flagCtr = $('#threadcreatepostflag');
        var jsubmit = $('#submit');
        var jmessage = $('#message');
        //页面加载后增加校验码,以判断是否更改
        $('INPUT.changeoversee,textarea.changeoversee').each(function () {
            var thisobj = $(this);
            thisobj.data('md5', $.md5(thisobj.val()));
        });
        //对版块选择复选框组处理:
        var jrelatedfids = $('#relatedfids');
        var bcgFidselects = null;
        if(jrelatedfids.length > 0){
            var Bckg_fidselects = $('#ckg_fidselects');
            var fidvals = jrelatedfids.val();
            if(Bckg_fidselects.length > 0){
                bcgFidselects = $("INPUT:checkbox",Bckg_fidselects);
                if(bcgFidselects.length > 0){
                    if(fidvals){
                        var fidarr = fidvals.split(/[,;\s]+/);
                        bcgFidselects.each(function(index,element){
                            if(fidarr.indexOf($(this).val()) > -1){
                                $(this).prop("checked",true);
                            }
                        });
                    }
                }
                $('INPUT:checkbox',Bckg_fidselects).bind('click',{"distele":"relatedfids"},function(evt){
                    var optHander = $("#"+evt.data.distele);
                    if(optHander.length>0){
                        var fidvalCur = optHander.val();
                        var fidCurArr = new Array();
                        if(fidvalCur.length > 0){
                            fidCurArr = fidvalCur.split(/[,;\s]+/);
                        }
                        var isChecked = $(this).prop("checked");
                        var theVal = parseInt($(this).val());
                        var newVal = fidCurArr.concat();
                        switch(theVal){
                            case 0://全选:
                                if(isChecked){
                                    newVal = Array();
                                    if(bcgFidselects && bcgFidselects.length > 2){
                                        bcgFidselects.each(function(index,element){
                                            if(parseInt($(this).val()) > 0)
                                            {
                                                newVal.push($(this).val());
                                                $(this).prop("checked",true);
                                            }
                                        });
                                    }
                                }
                                break;
                            case -1://不选:
                                if(isChecked){
                                    newVal = new Array(theVal.toString());
                                    bcgFidselects.each(function(index,element){
                                        if(parseInt($(this).val()) > -1)
                                            $(this).prop("checked",false);
                                    });
                                }
                                else{
                                    newVal = new Array();
                                }
                                break;
                            default:
                                if(isChecked){
                                    if(!xn.in_array(theVal.toString(),newVal)){
                                        newVal.push(theVal);
                                    }
                                    var dpos = newVal.indexOf("-1");
                                    if(dpos > -1) {
                                        $("INPUT:checkbox[value='-1']",Bckg_fidselects).prop("checked",false);
                                        newVal.splice(dpos,1);
                                    }
                                }
                                else{
                                    var hpos = newVal.indexOf(theVal.toString());
                                    if(hpos > -1){
                                         newVal.splice(hpos,1);
                                    }
                                }
                                break;
                        }
                        if(!ArrayEquals(newVal,fidCurArr)){
                            optHander.val(newVal.join(','));
                        }
                    }
                });
                Bckg_fidselects.hide();
            }
        }
        $("#selectfidsbtn").bind('click',{"distele":"ckg_fidselects"},function(evt){
            var selectfidsHander = $("#"+evt.data.distele);
            if(selectfidsHander.length>0){
                if(selectfidsHander.is(":visible"))
                    selectfidsHander.hide("fast");
                else
                    selectfidsHander.show("normal");
            }
        });

        //提交前筛查
        if (jsubmit.length > 0 && jmessage.length > 0) {
            jsubmit.on('click', function () {
                //关联版块全选处理
                if(bcgFidselects && bcgFidselects.length > 2){
                    var selectedfidArr = $("#relatedfids").val().split(/[,;\s]+/);
                    var unselectAllFid = false;
                    var t_p_s = -1;
                    bcgFidselects.each(function(index,element){
                        if(parseInt($(this).val()) > 0)
                        {
                            t_p_s = selectedfidArr.indexOf($(this).val());
                            if(t_p_s < 0){
                                unselectAllFid = true;
                                return false;
                            }
                        }
                    });
                    if(!unselectAllFid){
                        bcgFidselects.prop("checked",false);
                        $("#relatedfids").val("");
                    }
                }
				//筛除更改项:
<?php if($route != 'thread') { ?>
                if (typeof UM != 'undefined' && typeof UM.getEditor != 'undefined' && !!UM_Editor_MD5) {
                    var um_ids = xn.array_keys(UM_Editor_MD5);
                    if (typeof um_message == 'undefined' || !um_message)
                        um_message = UM.getEditor('message');
                    if (typeof UM_Editor_MD5[um_message.id] != 'undefined') {
                        var newMD5= $.md5(um_message.getContent());
                        if (UM_Editor_MD5[um_message.id] == newMD5) {
                            if($("#"+um_message.id+".changeoversee").length>0)
                                jmessage.prop('disabled',true);
                        }    //注:在提交成功前都不要修改md5校验码
                    }
                    $('INPUT.changeoversee,textarea.changeoversee').each(function () {
                        if (this.id && um_ids.length > 0) {
                            if (um_ids.indexOf(this.id) > -1)
                                return true;
                        }
                        var thisobj = $(this);
                        if (!!thisobj.data('md5') && thisobj.data('md5') == $.md5(thisobj.val()))
                            thisobj.prop('disabled', true);
                    });
                }
//<?php } ?>//筛除更改项结束

                if(flagCtr.length > 0 ) {
                    var flagval = flagCtr.val();
                    if (flagval.length > 0) {
                        var msgval = jmessage.val();
                        var flgars = {};
                        flgars[flagval] = {"u": uid, "g": gid};
                        var flagsJson = JSON.stringify(flgars).addslashes("'");
                        var rubyHead = '<ruby style="display:none;width:0;overflow:hidden" data-flags=\'';
                        var rubyTail = '\'>``ghx_flag``</ruby>';
                    }
                }
            });
        }
    });

$(document).ready(function() {
    $(".dropdown-item").each(function(){
        $(this).prop('title',$(this).data("path"));
    });
    // TEXTAREA输入框自动伸缩
    var xmessage = $('TEXTAREA.changeoversee:visible');
    xmessage.on('focus', function () {
        var ymsg = $(this);
        if (ymsg.t) {
            clearTimeout(ymsg.t);
            ymsg.t = null;
        }
        if(ymsg.data('vheight')==null){
            var csshv = ymsg.css("height");
            if(csshv == null) csshv = ymsg.height()+' px';
            ymsg.data('vheight',csshv);
        }
        ymsg.css('height', ymsg.data('vheight'));
    });
    xmessage.on('blur', function () {
        var zmsg = $(this);
        zmsg.t = setTimeout(function () {
            zmsg.css('height', '2.5rem');
        }, 1500);
    });
});
function fillthreadviewtpl(eleid,evt){
    ele_id = (typeof eleid == 'undefined'?"viwetemplate":eleid);
    $("#"+ele_id).val($(evt).data("path"));
}
//]]>
</script>
<?php
}
?>